/**
 * 
 */
package com.xbang.attendance.web.action.system.setuphouse;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.xbang.attendance.entity.system.Warehouse;
import com.xbang.attendance.service.SystemService;
import com.demo2do.lighturl.annotation.Action;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.SearchActionSupport;

/**
 * @author dev.zhang
 * 
 */
public class Search extends SearchActionSupport {

	private static final long serialVersionUID = -2293665695731096858L;

	private List<Warehouse> warehouses = new ArrayList<Warehouse>();

	private Log logger = LogFactory.getLog(Search.class);

	@Autowired
	private SystemService systemService;

	public String execute() throws Exception {

		logger.info(">>>>>>>>>>>> run search by action : setsystem/setuphouse/search");

		return "search";
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	@Action("/system/setuphouse/search/do")
	public String doSearch() throws Exception {

		String hqlSentence = "FROM Warehouse warehouse WHERE 1 = 1";
		if (searchComponent.getOrderParameters().isEmpty()){
			searchComponent.addSearchElement("orderBy.warehouse.code", "ASC");
		}
		Result result = systemService.searchByPage(hqlSentence, searchComponent, page);
		
		warehouses = result.getItems();
		page = result.getPage();

		return "r:/system/setuphouse/list";
	}

	/**
	 * @param systemService
	 */
	public void setSystemService(SystemService systemService) {
		this.systemService = systemService;
	}

	/**
	 * @return the warehouses
	 */
	public List<Warehouse> getWarehouses() {
		return warehouses;
	}

	/**
	 * @param warehouses the warehouses to set
	 */
	public void setWarehouses(List<Warehouse> warehouses) {
		this.warehouses = warehouses;
	}

	@Override
	public void resetCustomerSearchCriteria() {
		
	}
	
	
	
}
